#!/bin/env python
# -*- coding:utf-8
"""
@author:xingz
@file:Graph.py
@time:2021/11/21
"""
from __future__ import annotations
from typing import List, TypeVar, Generic, Optional
from graph.edge import Edge

V = TypeVar("V")


class Graph(Generic[V]):
    def __init__(self, vertices: List[V] = None):
        if vertices is None:
            vertices = []
        self._vertices: List[V] = vertices
        self._edges: List[List[Edge]] = [[] for _ in vertices]

    @property
    def vertex_count(self) -> int:
        return len(self._vertices)

    @property
    def edge_count(self) -> int:
        return len(self._edges)

    def add_vertex(self, vertex:V)->int:
        self._vertices.append(vertex)
        self._edges.append([])
        return self.vertex_count - 1

    def add_edge(self, edge: Edge):
        self._edges.append(edge)

